"use strict";

(function () {
  function r(e, n, t) {
    function o(i, f) {
      if (!n[i]) {
        if (!e[i]) {
          var c = "function" == typeof require && require;
          if (!f && c) return c(i, !0);
          if (u) return u(i, !0);
          var a = new Error("Cannot find module '" + i + "'");
          throw a.code = "MODULE_NOT_FOUND", a;
        }

        var p = n[i] = {
          exports: {}
        };
        e[i][0].call(p.exports, function (r) {
          var n = e[i][1][r];
          return o(n || r);
        }, p, p.exports, r, e, n, t);
      }

      return n[i].exports;
    }

    for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) {
      o(t[i]);
    }

    return o;
  }

  return r;
})()({
  1: [function (require, module, exports) {
    "use strict";

    loader.define(['pages/config/config'], function (config, require, exports, module, global) {
      var pageview = {};

      pageview.init = function () {
        var msg;
        var storage;
        storage = bui.storage({
          size: 0
        });
        bui.getPageParams(function (res) {
          msg = res.msg;

          if (msg instanceof Array) {
            storage.clear();

            for (var i in msg) {
              storage.set("member", msg[i], "phone");
            }
          }
        });
        msg = storage.get("member");
        console.log(msg);
        var groupid = '36';
        var data_ = {
          groupid: groupid
        };
        data_ = JSON.stringify(data_);
        bui.ajax({
          // url: 相对路径
          url: config.apiurl + "api/v1.0/getMuteList",
          data: data_,
          method: "post",
          headers: {
            'Content-Type': 'application/json'
          }
        }).then(function (res) {
          console.log(res);
          var mutelist = res.mutelist;
          var unmute = $(".unmute-list ul");
          var mute = $(".mute-list ul");
          unmute.html("");
          mute.html(""); // 显示列表

          var count = 0;

          for (var i in msg) {
            var li = $('<li class="bui-btn bui-box clearactive"></li>');
            var span1 = $('<div class="span1"></div>');
            var box = $('<div class="bui-box bui-box-align-middle"></div>');
            var item_img = $('<div class="item-img"></div>');
            var img = $('<img>');
            img.attr("src", msg[i].avatar_url);
            item_img.append(img);
            var item_detail = $('<div class="item-detail span1"></div>');
            var item_name = $('<div class="item-name"></div>');
            var item_intro = $('<div class="item-intro"></div>');
            item_name.text(msg[i].name);
            item_intro.text(msg[i].mobile);
            item_detail.append(item_name);
            item_detail.append(item_intro);
            box.append(item_img);
            box.append(item_detail);
            var ismute = $('<input type="checkbox" class="bui-switch danger mutecheck">');
            ismute.attr("id", msg[i].id);
            span1.append(box);
            li.append(span1);
            li.append(ismute);

            if ($.inArray(msg[i].id, mutelist) >= 0) {
              ismute.attr("checked", true);
              ismute.attr("name", "mute");
              mute.append(li);
              ++count;
            } else {
              ismute.prop("checked", false);
              ismute.attr("name", "unmute");
              unmute.append(li);
            }
          }

          if (count == msg.length) $("#muteall").prop("checked", true);
          $("#muteall").on("change", function () {
            var $that = $(this);
            var hasChecked = $that.prop("checked");
            console.log(groupid);
            var data_ = {
              groupid: groupid // mobile

            };
            data_ = JSON.stringify(data_);

            if (hasChecked) {
              bui.ajax({
                // url: 相对路径
                url: config.apiurl + "api/v1.0/muteall",
                data: data_,
                method: "post",
                headers: {
                  'Content-Type': 'application/json'
                }
              }).then(function (res) {
                console.log(res);
                bui.refresh();
              }, function (res, status) {
                console.log(status);
              });
            } else {
              bui.ajax({
                // url: 相对路径
                url: config.apiurl + "api/v1.0/removeMuteGroup",
                data: data_,
                method: "post",
                headers: {
                  'Content-Type': 'application/json'
                }
              }).then(function (res) {
                console.log(res);
                bui.refresh();
              }, function (res, status) {
                console.log(status);
              });
            }
          });
          $(".mutecheck").on("change", function () {
            var $that = $(this);
            var id = $that.attr("id");
            var hasChecked = $that.prop("checked");
            console.log(id, hasChecked);

            if (hasChecked) {
              var uiPrompt = bui.prompt("请输入禁言时间(min)", function (e) {
                var text = $(e.target).text();

                if (text == "取消") {
                  this.close();
                } else {
                  if (this.value()) {
                    // 获取输入的值
                    // bui.hint("您好,"+this.value());
                    var rule = /^\d+$/;

                    if (rule.test(this.value())) {
                      console.log(this.value());
                      var data_ = {
                        userid: id,
                        groupid: groupid,
                        minute: this.value()
                      };
                      data_ = JSON.stringify(data_);
                      bui.ajax({
                        // url: 相对路径
                        url: config.apiurl + "api/v1.0/mute",
                        data: data_,
                        method: "post",
                        headers: {
                          'Content-Type': 'application/json'
                        }
                      }).then(function (res) {
                        console.log(res); // 刷新还是前端改布局

                        bui.refresh();
                      }, function (res, status) {
                        console.log(status);
                      });
                    } else {
                      bui.hint("请输入正确数字");
                    }

                    this.close();
                  } else {
                    bui.hint("禁言时间不能为空");
                  }
                }
              });
            } else {
              var data_ = {
                userid: id,
                groupid: groupid
              };
              data_ = JSON.stringify(data_);
              bui.ajax({
                // url: 相对路径
                url: config.apiurl + "api/v1.0/removeMuteUser",
                data: data_,
                method: "post",
                headers: {
                  'Content-Type': 'application/json'
                }
              }).then(function (res) {
                console.log(res); // 刷新还是前端改不局？

                bui.refresh();
              }, function (res, status) {
                console.log(status);
              });
            } // if (hasChecked) {
            //     
            // } else {
            //     bui.confirm("确定要关闭蓝牙吗", function(e) {
            //         var text = $(e.target).text();
            //         if (text == "确定") {
            //             //do something
            //             return;
            //         } else {
            //             $that.prop("checked", !hasChecked)
            //             return;
            //         }
            //         this.close();
            //     });
            // }

          });
        }, function (res, status) {
          console.log(status);
        });
      };

      pageview.init();
      return pageview;
    });
  }, {}]
}, {}, [1]);